#include "csocket.h"
#include <QUrl>
#include <QDebug>

CSOCKET::CSOCKET(QObject *parent) : QObject(parent)
{
    m_websocket = new QWebSocket();
    connect(m_websocket, &QWebSocket::connected, this, &CSOCKET::onConnected);
    connect(m_websocket, &QWebSocket::disconnected, this, &CSOCKET::onDisConnected);
    connect(m_websocket, &QWebSocket::textMessageReceived, this, &CSOCKET::onTextMessageReceived);
     connect(m_websocket, &QWebSocket::pong, this, &CSOCKET::onpong);
    connect(m_websocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError)));
    m_websocket->open(QUrl("wss://socket.idcd.com:1443"));

}

CSOCKET::~CSOCKET(){

}

void CSOCKET::onpong(quint64 elapsedTime, const QByteArray &payload){
 qDebug()<<"onpong"<<elapsedTime<<payload;
}

void CSOCKET::onConnected(){
    qDebug()<<"onConnected";

    m_websocket->ping("111");

}

void CSOCKET::onDisConnected(){
     qDebug()<<"onDisConnected";

}

void CSOCKET::onTextMessageReceived(const QString &message){
     qDebug()<<"onTextMessageReceived"<<message;
}

void CSOCKET::onError(QAbstractSocket::SocketError error){
     qDebug()<<"onError"<<error;
}

